package com.tool.configuration.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2024/1/23 20:04
 * 测试websocket
 */
@Component
public class webSocketTask {
    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * 每隔5秒向客户的发送消息
     */
//    @Scheduled(cron = "0/5 * * * * ? ")
    public void executeTask() {
        webSocketServer.sendToAllClient("这是来自服务器的消息：" + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }
}
